﻿/// <reference path="jquery-1.4.2.min.js" />
/// <reference path="swfobject/swfobject-2.2.js" />

function addCookie() { // 收藏本站
    if (document.all) {
        window.external.addFavorite('http://www.AUV5.com', 'AUV5（唯5网）！');
    }
    else if (window.sidebar) {
        window.sidebar.addPanel('AUV5（唯5网）！', 'http://www.AUV5.com', "");
    }
}
function setHomepage() {//设为首页
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(window.location.href);
    } else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', window.location.href);
    } else {
        alert('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!');
    }
}

//取消事件默认操作
function preventDefault(eventObject) {
    eventObject = eventObject || getEventObject(eventObject);
    if (eventObject.preventDefault) {//W3C方式 
        eventObject.preventDefault();
    }
    else
        eventObject.returnValue = false; //MSIE
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    }
    else {
        return "";
    }
}

//Cookie

var Cookies = {};
//设置Cookies  
Cookies.set = function (name, value) {
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : '/';
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
};
//读取Cookies  
Cookies.get = function (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while (i < clen) {
        j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }
    return '';
};
//清除Cookies  
Cookies.clear = function (name) {
    if (Cookies.get(name)) {
        var expdate = new Date();
        expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
        Cookies.set(name, "", expdate);
    }
};

var getCookieVal = function (offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
};




//open Dialog
function openDialog(href, width, height, top, left) {
    top = top || 0;
    left = left || 100;
    width = width || 595;
    height = height || 768;
    window.open(href, '', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',toolbar=0,menubar=0,scrollbars=yes,resizable=0,location=no');
    return false;
}

function ShareToSina(shareUrl, shareTitle, sharepic) {
    var _w = 16, _h = 16;
    var param = {
        url: shareUrl,
        type: '3',
        count: '0', /**是否显示分享数，1显示(可选)*/
        appkey: '', /**您申请的应用appkey,显示分享来源(可选)*/
        title: shareTitle, /**分享的文字内容(可选，默认为所在页面的title)*/
        pic: sharepic, /**分享图片的路径(可选)*/
        ralateUid: '', /**关联用户的UID，分享微博会@该用户(可选)*/
        language: 'zh_cn', /**设置语言，zh_cn|zh_tw(可选)*/
        rnd: new Date().valueOf()
    };
    var temp = [];
    for (var p in param) {
        temp.push(p + '=' + encodeURIComponent(param[p] || ''));
    };
    document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="' + _w + '" height="' + _h + '"></iframe>');
}

function ShareToQzone(shareUrl, shareTitle, sharepic) {
    var p = {
        url: shareUrl,
        showcount: '0', /*是否显示分享总数,显示：'1'，不显示：'0' */
        desc: shareTitle, /*默认分享理由(可选)*/
        summary: shareTitle, /*分享摘要(可选)*/
        title: shareTitle, /*分享标题(可选)*/
        site: 'http://www.auv5.com/', /*分享来源 如：腾讯网(可选)*/
        pics: sharepic, /*分享图片的路径(可选)*/
        style: '203',
        width: 16,
        height: 16
    };
    var s = [];
    for (var i in p) {
        s.push(i + '=' + encodeURIComponent(p[i] || ''));
    }
    document.write(['<a version="1.0" class="qzOpenerDiv" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?', s.join('&'), '" target="_blank">分享</a>'].join(''));
}

var ScrollTitle = function (mes) {
    //滚动标题，显示站内提示信息
    //间隔
    var interval = 500;
    //消息完全显示后暂停滚动的时间  2s
    var pause = 2000;
    //切换回原标题的时间   3s
    var stop = 3000;
    //页面的原标题
    var title = document.title;
    //消息的长度
    var len = mes.length;
    //循环标记
    var loop = 0;

    //显示滚动信息（以截字符的形式）
    function ShowTitle(mes, count) {
        //滚进及暂停
        var m = len + pause / interval;
        if (count <= m) {
            document.title = mes.substr(0, count);
        }
        //滚出
        var n = m + len;
        if (count > m & count < n) {
            document.title = mes.substr(len - n + count, n - count);
        }
        //显示原标题
        if (count >= n) {
            document.title = title;
        }
        loop++;
        //循环次数 长度*2+暂停
        if (loop > 2 * len + pause / interval + stop / interval) {
            loop = 0;
        }
        setTimeout(function () {
            ShowTitle(mes, loop);
        }, 1000);
    };
    return {
        show: function show() {
            ShowTitle(mes, loop);
        }
    };

};
$(function () {
    var mes = "";
    if ($('#lbMesCount').length > 0) {
        //滚动信息
        mes = "您有" + $('#lbMesCount').text() + "条新短消息";
        len = mes.length;
    }
    if (mes != "") {
        new ScrollTitle(mes).show();
    }
});
//使用colorbox打开页面
function openColorBox(url, width, height) {
    width = width || 440;
    height = height || 330;
    $.colorbox({
        iframe: true,
        innerWidth: width,
        innerHeight: height,
        href: url
    });
}

// 播放背景音乐
function playSound() {
    $('<div>').html(AC_FL_RunContent('id', 'pmsoundplayer', 'name', 'pmsoundplayer', 'width', '0', 'height', '0', 'src', '/!sounds/soundplayer.swf', 'FlashVars', 'sFile=/!sounds/pm_2.mp3', 'menu', 'false', 'allowScriptAccess', 'sameDomain', 'swLiveConnect', 'true')).appendTo(document.body);
}

//显示错误信息
function showMessage(mes, classname) {
    classname = classname || "warninginfo";
    $('<div>').addClass('popinfo ' + classname).prependTo($('.main_left')[0]).html(mes);
}
function showNotice(mes) {
    showMessage(mes);
}
function showSuccess(mes) {
    showMessage(mes, "correctinfo");
}
function showError(mes) {
    showMessage(mes, "errorinfor");
}


//导航换图片
function MM_preloadImages() { //v3.0
    var d = document; if (d.img) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
//load validate code
function RefreshValidateCode(controlId) {
    var time = new Date().getTime();
    $(controlId).attr("src", "../Handler/MathValidateCodeHandler.ashx?r=" + time);
}


//load the dropdownlist of birthday
var bigArray = new Array(1, 3, 5, 7, 8, 10, 12);
function OnSelectChange(year, month, day) {
    if (month.value == 2)//选中的月份为2月
    {
        if (checkYear(year.value))//闰年
        {
            fillDay(day, 29);
        }
        else {
            fillDay(day, 28);
        }
    }
    else {
        if (inArray(month.value, bigArray)) {
            fillDay(day, 31);
        }
        else {
            fillDay(day, 30);
        }
    }
}
function checkYear(year) {
    return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}
function fillDay(day, days) {
    while (day.options.length > 0) {
        day.remove(0);
    }
    for (i = 1; i <= days; i++) {
        var oOption = document.createElement("OPTION");
        if (i < 10) {
            oOption.innerText = "0" + i;
        }
        else {
            oOption.innerText = i;
        }
        oOption.value = i;
        day.appendChild(oOption);
    }
}
function inArray(oObj, oArray) {
    for (i = 0; i < oArray.length; i++) {
        if (oObj == oArray[i]) {
            return true;
        }
    }
    return false;
}
